# coding: utf8
# try something like
def index(): 


    return dict(fav = db(db.fc.category=='favorite').select(db.fc.feature, db.fc.count, orderby=~db.fc.count, limitby=(0, 20)),
                spam = db(db.fc.category=='spam').select(db.fc.feature, db.fc.count ,orderby=~db.fc.count, limitby=(0, 20)),
                category = db().select(db.cc.ALL) )


from docclass import getwords

def trends():

    res = db().select(db.twitter_favorite.ALL, orderby=~db.twitter_favorite.twitter_created_at, limitby=(0,20))
    
    ret = {}
    trends = {}
    for r in res:
        words = getwords(r.text)
        for w in words:
            trends.setdefault(w, 0)
            trends[w] += 1
        
        _date = str(r.twitter_created_at.date())
        ret.setdefault(_date, {})
        ret[_date] = trends
        
    return dict(ret=ret)
